<?php

/**
 *
 * @author ben <ben@spicatech.cn>  Created on 2015-12-1
 */
class ServiceOrderService {

    protected $order;

    /**
     * 
     * @param ServiceOrder $order
     */
    public function __construct(ServiceOrder $order) {
        $this->order = $order;
    }

    /*     * *
     * 
     */

    public function updateStatus($status) {
        if ($this->order->order_status != ServiceOrder::ORDER_STATUS_UNHANDLED) {
            throw new RuntimeException('请勿重复处理');
        }
        $this->order->order_status = $status;
        $this->order->update(['order_status']);
        $this->notifyAfterSuccess();
    }

    /**
     * @todo 通知
     * @return boolean
     */
    public function notifyAfterSuccess() {
        if ($this->order->order_status != ServiceOrder::ORDER_STATUS_SUCCESS) {
            return false;
        }
        $point = ServicePoint::findById($this->order->point_id);
        if (!$point) {
            return false;
        }
        $mobiles = explode(',', $point->link_phone);
    }

}
